package com.snowcattle.game.service.time;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;


public class Time {

    public final Logger log = LoggerFactory.getLogger(Time.class);

    /**
     * 服务器的运行时间
     */
    public int currTime = 0;
    public long startTime = 0;
    public int tick = 0;
    public static Date currDate = null;

    public void init() {
        currDate = new Date();
        startTime = currDate.getTime();
    }

    public long update() {
        currDate = new Date();
        long t = currDate.getTime() - startTime;
        long ret = t - currTime;
        if (ret < 0) {
            startTime += ret;
            ret = 0;
            t = currTime;
        }
        currTime = (int) t;
        return ret;
    }

    public int elapseTime(long time) {
        return (int) (time - startTime);
    }

    public long currentTimeMillis(int t) {
        return startTime + t;
    }
}
